package remote
{
	import model.Paciente;
	
	import mx.controls.Alert;
	import mx.rpc.AbstractOperation;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	import mx.rpc.remoting.mxml.RemoteObject;

	public class PacienteRO extends mx.rpc.remoting.RemoteObject
	{
		private static var singleton:PacienteRO;
		private var operation: AbstractOperation;

		
		public function PacienteRO(destination:String=null)
		{
			destination = "PacienteFacade";
			super(destination);
			operation = new AbstractOperation();
			operation.addEventListener(FaultEvent.FAULT, catchError);
		}
		
		public static function getInstance():PacienteRO{  
			if (singleton == null){  
				singleton = new PacienteRO();  
			}  
			return singleton;                 
		}
		
		public function catchError(event:FaultEvent):void{
			Alert.show(event.fault.toString(), "Erro");
			this.showBusyCursor = false;
		}
		
		public function saveOrUpdate(paciente:Paciente, result:Function):void {
			this.showBusyCursor = true;
			operation = this.getOperation("saveOrUpdate");
			operation.addEventListener(ResultEvent.RESULT, result);
			operation.arguments = new Array(paciente);
			operation.send();
		}
		
		

	}
}